package com.yhally.eureka.controller;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/discover")
public class DiscoverController {

    @Resource
    private DiscoveryClient discoveryClient;

    @GetMapping("/list")
    public List<String> list() {
        return discoveryClient.getServices();
    }

    @GetMapping("/list/{serviceId}")
    public List<ServiceInstance> listServiceInstance(@PathVariable String serviceId) {
        return discoveryClient.getInstances(serviceId);
    }

}
